class CreateEntries < ActiveRecord::Migration
  def self.up
    create_table :entries do |t|
      t.column :lock_version,   :integer,   :null => false
      t.column :title,          :string,    :null => false, :limit => 50
      t.column :resource_id,    :integer,   :null => false
      t.column :resource_type,  :string,    :null => false, :limit => 7
      t.column :position,       :integer,   :null => false
      t.column :holder_id,      :integer,   :null => false
      t.column :user_id,        :integer,   :null => false
      t.column :messages_count, :integer,   :null => false, :default => 0
      t.column :created_at,     :timestamp, :null => false
      t.column :updated_at,     :timestamp, :null => false
    end

    add_index :entries, [ :title, :holder_id, :user_id ], :unique => true
  end

  def self.down
    drop_table :entries
  end
end
